package domain.service;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.Charset;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;



public class TrackIp {
	public TrackIp()
	{
        try {
            URL url = new URL("http://o2tv.vn/ip.php?ip=72.167.232.197");
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setReadTimeout(500000);
			connection.setConnectTimeout(1000000);
			BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), Charset.forName("iso-8859-1")));
			String content = "";
			while(1==1)
			{
				String str = reader.readLine();
				if(str==null) break;
				content+=str;
				
			}
            Document doc = Jsoup.parse(content); 
            Elements ips = doc.select("span");
            if(ips.size() > 0)
            {
            	for(int i=0;i<ips.size();i++)
            	{
            		if(ips.get(i).text().indexOf("inetnum")!= -1) //dai ip
            		{
            			System.out.println(ips.get(i));
            		}
            		if(ips.get(i).text().indexOf("netname")!= -1) //dai ip
            		{
            			System.out.println(ips.get(i));
            		}
            	}
            }
            
            System.out.println(doc);
        } catch (MalformedURLException e) {
            // ...
        } catch (IOException e) {
            // ...
        }

	}
	public static void main( String args[])
	{
		new TrackIp();
	}
}
